/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package View;

import Controller.StarClusterController;
import Model.DataSet;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Snowangelic
 */
public class DataSetTableModel extends AbstractTableModel implements TableModelListener {
    DataSet dataSet;
    StarClusterController dataController;

    DataSetTableModel(){
    }

    @Override
    public String getColumnName(int col) {
        if(dataSet==null) return null;
        else if (col==0) return null;
        else if(col<=dataSet.getAttributeNbr()) return dataSet.getAttributeName(col-1);
        else return dataSet.getClusterizationName(col-1-dataSet.getAttributeNbr());
    }

    public int getRowCount() {
        if(dataSet==null) return 0;
        else return dataSet.getActionNbr()+1;
        //if(valueArray==null) return 0;
        //else return valueArray.length;
    }

    public int getColumnCount() {
        if(dataSet==null) return 0;
        else if (dataSet.getAttributeNbr()==0) return 0;
        else return dataSet.getAttributeNbr()+1+dataSet.getClusterizationNbr();
        //if(valueArray==null) return 0;
        //else return valueArray[0].length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if(dataSet==null) return null;
        else if(rowIndex >=getRowCount() || columnIndex >=getColumnCount()) return null;
        else if(rowIndex ==getRowCount()-1) return null;
        else if(columnIndex==0) return rowIndex+1;
        else if(columnIndex<=dataSet.getAttributeNbr())return dataSet.getValue(rowIndex,columnIndex-1);
        else return dataSet.getClusterization(columnIndex-1-dataSet.getAttributeNbr()).getClusterName(dataSet.getAction(rowIndex));
        //return rowIndex+columnIndex;
    }

    void setController(StarClusterController dataController) {
        this.dataController=dataController;
    }

    void setDataSet(DataSet dataSet) {
        this.dataSet=dataSet;

    }

    public boolean isCellEditable(int row, int col) {
        if (col>=1) return true;
        else return false;
    }

    public void setValueAt(Object value, int row, int col) {
        if(row>=dataSet.getActionNbr()) dataController.addAction();
        dataController.setValue(row, col-1, value.toString());
    }


    public void tableChanged(TableModelEvent e) {
    }


}
